package com.fengzhilian.timewheel.wheel;

import com.fengzhilian.timewheel.container.Bucket;
import com.fengzhilian.timewheel.container.DelayQueue;

/**
 * 秒轮
 * @author 郭智峰
 * @Date 2019年12月25日
 */
public class SecondTimeWheel extends TimeWheel {

  public SecondTimeWheel(long currentTimestamp, String timeWheelType, DelayQueue delayQueue){
      this.interval=60*1000;
      this.tickMs=1000;
      this.wheelSize=60;
      this.timeWheelType=timeWheelType;
      this.buckets = new Bucket[wheelSize];
      for (int i = 0; i < wheelSize; i++) {
          buckets[i] = new Bucket();
          this.delayQueue=delayQueue;
          this.delayQueue.addBucket(buckets[i]);
      }
      this.currentTimestamp = currentTimestamp;
  }

    @Override
    public TimeWheel getOverflowWheel() {
        if (overflowWheel == null) {
            synchronized (this) {
                if (overflowWheel == null) {
                    overflowWheel = new HourTimeWheel(this.currentTimestamp,timeWheelType,delayQueue);
                }
            }
        }
        return overflowWheel;
    }
}
